package com.kele.encryption.config;

import com.kele.encryption.advice.DecryptRequestBodyAdvice;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.web.method.ControllerAdviceBean;

@AutoConfiguration
@ConditionalOnProperty(value = "data-encryptor.enable", havingValue = "true")
public class EncryptionAutoConfiguration {

    private final EncryptionProperties encryptionProperties;

    public EncryptionAutoConfiguration(EncryptionProperties encryptionProperties) {
        this.encryptionProperties = encryptionProperties;
    }

    /**
     * 用ControllerAdviceBean包装，确保Spring MVC能够识别到Advice
     * @return
     */
//    @Bean
//    public ControllerAdviceBean decryptRequestBodyAdviceBean() {
//        return new ControllerAdviceBean(new DecryptRequestBodyAdvice(encryptionProperties));
//    }

    /**
     * 注册普通的Bean，确保Autowired可以注入
     * @return
     */
//    @Bean
//    public DecryptRequestBodyAdvice decryptRequestBodyAdvice() {
//        return new DecryptRequestBodyAdvice(encryptionProperties);
//    }

}
